// TaskPane.cpp : implementation of the CTaskPane class
//

#include "stdafx.h"
#include "TaskPane.h"
#include "../AnyCADENU/Resource.h"
#include "PlugsConfigure.h"
#include "GeomApp.h"
#include "MessageGeomUI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


class CXporterVisiter : public IXportItemVisitor
{
public:
	CXporterVisiter(CTaskPane& wndTaskPane)
		:m_refTaskPane(wndTaskPane),
		m_nCurPageGroup(-1)
	{
		
	}
	void InitExporters()
	{
		m_nCurPageGroup = m_refTaskPane.AddGroup (_T("Export"));
		m_nCurID = ID_FILE_EXPORT_BEGIN;
		GetCPlugsConfigure().VisitExporterItem(this);
	}
	void InitImporters()
	{
		m_nCurPageGroup = m_refTaskPane.AddGroup (_T("Import"));
		m_nCurID = ID_FILE_IMPORT_BEGIN;
		GetCPlugsConfigure().VisitImporterItem(this);
	}
	virtual void OnVisitItem(XportItem* pItem)
	{
		m_refTaskPane.AddXporter(m_nCurID, pItem->guid);
		m_refTaskPane.AddTask (m_nCurPageGroup, pItem->szExt, -1, m_nCurID++);

	}
protected:
	CTaskPane& m_refTaskPane;
	int m_nCurPageGroup;
	int m_nCurID;
};

/////////////////////////////////////////////////////////////////////////////
// CTaskPane

BEGIN_MESSAGE_MAP(CTaskPane, CBCGPTasksPane)
	//{{AFX_MSG_MAP(CTaskPane)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTaskPane construction/destruction

CTaskPane::CTaskPane()
{
	// TODO: add one-time construction code here

}

CTaskPane::~CTaskPane()
{
}

/////////////////////////////////////////////////////////////////////////////
// CTaskPane message handlers

int CTaskPane::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CBCGPTasksPane::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	SetCaption (_T("Documents"));
	//SetIconsList (IDB_TASKS, 16);

	EnableNavigationToolbar (FALSE);

	EnableWrapLabels (TRUE);
	EnableOffsetCustomControls (FALSE);

	//---------------------------------
	m_nDocumentsGroup = AddGroup (_T("Open a document"), FALSE, TRUE);
	// Add MRU list:
	AddMRUFilesList (m_nDocumentsGroup);
	AddTask (m_nDocumentsGroup, _T("More Documents..."), 0, ID_FILE_OPEN);

	//---------------------------------------------
	CXporterVisiter xporter(*this);
	xporter.InitExporters();
	xporter.InitImporters();


	return 0;
}

void CTaskPane::UpdateMRUFilesList ()
{
	AddMRUFilesList (m_nDocumentsGroup);
	RedrawWindow ();
}

void CTaskPane::UpdateToolbar ()
{
	m_wndToolBar.RedrawWindow ();
}

void CTaskPane::AddXporter(int nID, const CString& szGUID)
{
	m_mapCommand[nID] = szGUID;
}
void CTaskPane::OnImportFile(UINT nID)
{
	CString szGUID;
	if(m_mapCommand.Lookup(nID, szGUID))
	{
		SendMessageToActiveView(WM_GEOM_COMMON_MESSAGE, GCM_FILE_IMPORT, (LPARAM)&szGUID);
	}
}

void CTaskPane::OnExportFile(UINT nID)
{
	CString szGUID;
	if(m_mapCommand.Lookup(nID, szGUID))
	{
		SendMessageToActiveView(WM_GEOM_COMMON_MESSAGE, GCM_FILE_EXPORT, (LPARAM)&szGUID);
	}
	
}